package com.hsj.goldstore.mvp.view;


import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.Loader;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.hsj.goldstore.R;
import com.hsj.goldstore.base.BaseMvpActivity;
import com.hsj.goldstore.base.PresenterFactory;
import com.hsj.goldstore.base.PresenterLoader;
import com.hsj.goldstore.mvp.present.MainPresent;
import com.hsj.goldstore.utils.Helper;


import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends BaseMvpActivity<MainPresent, MainView> implements MainView, RadioGroup.OnCheckedChangeListener {


    @BindView(R.id.fragment)
    FrameLayout fragment;
    @BindView(R.id.rb_store)
    RadioButton rbStore;
    @BindView(R.id.rb_goods)
    RadioButton rbGoods;
    @BindView(R.id.rb_my)
    RadioButton rbMy;
    @BindView(R.id.rg_bottom)
    RadioGroup rgBottom;

    @Override
    protected int getResouseId() {
        return R.layout.activity_main;
    }


    @Override
    protected void initView() {
        rgBottom.setOnCheckedChangeListener(this);
        presenter.init();
        if (!hasPermission(Manifest.permission.CALL_PHONE)) {
            requestPerssion(0, "没有拨打电话权限", Manifest.permission.CALL_PHONE);
        }

    }

    @Override
    public void callPhone() {
        super.callPhone();
        Intent intent = new Intent(Intent.ACTION_DIAL);
        Uri uri = Uri.parse("tel:" + "10086");
        intent.setData(uri);
        startActivity(intent);

    }

    @Override
    protected void initData() {
        presenter.showStore();
    }


    @Override
    public Loader<MainPresent> onCreateLoader(int i, Bundle bundle) {
        return new PresenterLoader<>(this, new PresenterFactory<MainPresent>() {
            @Override
            public MainPresent create() {
                return new MainPresent();
            }
        });
    }


    @Override
    public void showDataResult(String result) {

    }

    @Override
    public FragmentManager getManager() {
        return getSupportFragmentManager();
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }


    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int i) {
        switch (i) {
            case R.id.rb_store:
                presenter.showStore();
                break;
            case R.id.rb_goods:
                presenter.showGoods();
                break;
            case R.id.rb_my:
                presenter.showMy();
                break;
            default:
                break;
        }
    }


}
